import {createRouter, createWebHistory, RouteRecordRaw} from 'vue-router'
import bar from 'nprogress'
import 'nprogress/nprogress.css'
import base from './modules/base'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    component: () => import('~/layout/index.vue'),
    redirect: '/index',
    meta: {
      title: '首页',
      icon: 'home-4-line',
      affix: true,
    },
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('~/base/home.vue'),
        meta: {
          title: '首页',
          icon: 'home-4-line',
          affix: true,
        },
      },
      {
        path: 'map',
        name: 'Map',
        component: () => import('~/amap.vue')
      },
      {
        path: 'panel',
        name: 'Panel',
        component: () => import('~/car/BatteryPanel.vue')
      },
      {
        path: 'bmap',
        name: 'bMap',
        // component: () => import('~/bmap.vue')
        component: () => import('~/bmapgl.vue')
      },
    ],
  },
  ...base
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})


router.beforeEach((to, from, next) => {
  document.title = import.meta.env.VITE_APP_TITLE as string

  bar.start()

  setTimeout(next, 500)
})

router.afterEach(() => bar.done())

export default router
